package co.yixiang.mall.biz.commission.controller;

import co.yixiang.common.core.annotation.AnonymousAccess;
import co.yixiang.mall.biz.commission.service.CommissionService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/commission")
@EnableScheduling
@Log4j2
public class CommissionController {
    private Integer type = 0;

    @Autowired
    CommissionService commissionService;

    @PostMapping("/service")
    @AnonymousAccess
    public Integer serviceCharge(){
        Integer charge = commissionService.serviceCharge();
        if(charge == 1){
            log.info("订单结算成功");
        }else if(charge == 2){
            log.error("订单结算异常");
        }else{
            log.error("未知异常");
        }
        return charge;
    }

    /** 每天0时结算店铺服务费 */
    @Scheduled(cron = "0 0 0 * * ?")
    public void serviceDailyQz(){
        commissionService.serviceCharge();
    }

    /**
     * 每天0时1分将店铺的今日是否结算改为未结算
     * */

    //@Scheduled(cron = "0 1 0 * * ?")
    public void serviceSetQz(){
            commissionService.SettlementSet();

    }
}
